package com.google.android.vending.expansion.downloader.impl;

import android.content.ContentResolver;
import android.os.Looper;
import android.util.Log;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.entity.AbstractHttpEntity;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.RequestWrapper;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.BasicHttpProcessor;
import org.apache.http.protocol.HttpContext;

public final class AndroidHttpClient
  implements HttpClient
{
  public static long DEFAULT_SYNC_MIN_GZIP_BYTES = 0L;
  private static final int SOCKET_OPERATION_TIMEOUT = 60000;
  private static final String TAG = "AndroidHttpClient";
  static Class<?> sSslSessionCacheClass;
  private static final HttpRequestInterceptor sThreadCheckInterceptor;
  private volatile LoggingConfiguration curlConfiguration;
  private final HttpClient delegate;
  private RuntimeException mLeakedException = new IllegalStateException("AndroidHttpClient created and never closed");

  static
  {
    try
    {
      sSslSessionCacheClass = Class.forName("android.net.SSLSessionCache");
      label8: DEFAULT_SYNC_MIN_GZIP_BYTES = 256L;
      sThreadCheckInterceptor = new HttpRequestInterceptor()
      {
        public void process(HttpRequest paramAnonymousHttpRequest, HttpContext paramAnonymousHttpContext)
        {
          if ((Looper.myLooper() != null) && (Looper.myLooper() == Looper.getMainLooper()))
            throw new RuntimeException("This thread forbids HTTP requests");
        }
      };
      return;
    }
    catch (Exception localException)
    {
      break label8;
    }
  }

  private AndroidHttpClient(ClientConnectionManager paramClientConnectionManager, HttpParams paramHttpParams)
  {
    this.delegate = new DefaultHttpClient(paramClientConnectionManager, paramHttpParams)
    {
      protected HttpContext createHttpContext()
      {
        BasicHttpContext localBasicHttpContext = new BasicHttpContext();
        localBasicHttpContext.setAttribute("http.authscheme-registry", getAuthSchemes());
        localBasicHttpContext.setAttribute("http.cookiespec-registry", getCookieSpecs());
        localBasicHttpContext.setAttribute("http.auth.credentials-provider", getCredentialsProvider());
        return localBasicHttpContext;
      }

      protected BasicHttpProcessor createHttpProcessor()
      {
        BasicHttpProcessor localBasicHttpProcessor = super.createHttpProcessor();
        localBasicHttpProcessor.addRequestInterceptor(AndroidHttpClient.sThreadCheckInterceptor);
        localBasicHttpProcessor.addRequestInterceptor(new AndroidHttpClient.CurlLogger(AndroidHttpClient.this, null));
        return localBasicHttpProcessor;
      }
    };
  }

  public static AbstractHttpEntity getCompressedEntity(byte[] paramArrayOfByte, ContentResolver paramContentResolver)
    throws IOException
  {
    if (paramArrayOfByte.length < getMinGzipSize(paramContentResolver))
      return new ByteArrayEntity(paramArrayOfByte);
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    GZIPOutputStream localGZIPOutputStream = new GZIPOutputStream(localByteArrayOutputStream);
    localGZIPOutputStream.write(paramArrayOfByte);
    localGZIPOutputStream.close();
    ByteArrayEntity localByteArrayEntity = new ByteArrayEntity(localByteArrayOutputStream.toByteArray());
    localByteArrayEntity.setContentEncoding("gzip");
    return localByteArrayEntity;
  }

  public static long getMinGzipSize(ContentResolver paramContentResolver)
  {
    return DEFAULT_SYNC_MIN_GZIP_BYTES;
  }

  public static InputStream getUngzippedContent(HttpEntity paramHttpEntity)
    throws IOException
  {
    Object localObject = paramHttpEntity.getContent();
    if (localObject == null)
      return localObject;
    Header localHeader = paramHttpEntity.getContentEncoding();
    if (localHeader == null)
      return localObject;
    String str = localHeader.getValue();
    if (str == null)
      return localObject;
    if (str.contains("gzip"))
      localObject = new GZIPInputStream((InputStream)localObject);
    return localObject;
  }

  public static void modifyRequestToAcceptGzipResponse(HttpRequest paramHttpRequest)
  {
    paramHttpRequest.addHeader("Accept-Encoding", "gzip");
  }

  public static AndroidHttpClient newInstance(String paramString)
  {
    return newInstance(paramString, null);
  }

  // ERROR //
  public static AndroidHttpClient newInstance(String paramString, android.content.Context paramContext)
  {
    // Byte code:
    //   0: new 180	org/apache/http/params/BasicHttpParams
    //   3: dup
    //   4: invokespecial 181	org/apache/http/params/BasicHttpParams:<init>	()V
    //   7: astore_2
    //   8: aload_2
    //   9: iconst_0
    //   10: invokestatic 187	org/apache/http/params/HttpConnectionParams:setStaleCheckingEnabled	(Lorg/apache/http/params/HttpParams;Z)V
    //   13: aload_2
    //   14: ldc 13
    //   16: invokestatic 191	org/apache/http/params/HttpConnectionParams:setConnectionTimeout	(Lorg/apache/http/params/HttpParams;I)V
    //   19: aload_2
    //   20: ldc 13
    //   22: invokestatic 194	org/apache/http/params/HttpConnectionParams:setSoTimeout	(Lorg/apache/http/params/HttpParams;I)V
    //   25: aload_2
    //   26: sipush 8192
    //   29: invokestatic 197	org/apache/http/params/HttpConnectionParams:setSocketBufferSize	(Lorg/apache/http/params/HttpParams;I)V
    //   32: aload_2
    //   33: iconst_0
    //   34: invokestatic 202	org/apache/http/client/params/HttpClientParams:setRedirecting	(Lorg/apache/http/params/HttpParams;Z)V
    //   37: aconst_null
    //   38: astore_3
    //   39: aload_1
    //   40: ifnull +46 -> 86
    //   43: getstatic 42	com/google/android/vending/expansion/downloader/impl/AndroidHttpClient:sSslSessionCacheClass	Ljava/lang/Class;
    //   46: astore 16
    //   48: aconst_null
    //   49: astore_3
    //   50: aload 16
    //   52: ifnull +34 -> 86
    //   55: getstatic 42	com/google/android/vending/expansion/downloader/impl/AndroidHttpClient:sSslSessionCacheClass	Ljava/lang/Class;
    //   58: iconst_1
    //   59: anewarray 36	java/lang/Class
    //   62: dup
    //   63: iconst_0
    //   64: ldc 204
    //   66: aastore
    //   67: invokevirtual 208	java/lang/Class:getConstructor	([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;
    //   70: iconst_1
    //   71: anewarray 4	java/lang/Object
    //   74: dup
    //   75: iconst_0
    //   76: aload_1
    //   77: aastore
    //   78: invokevirtual 213	java/lang/reflect/Constructor:newInstance	([Ljava/lang/Object;)Ljava/lang/Object;
    //   81: astore 23
    //   83: aload 23
    //   85: astore_3
    //   86: aload_2
    //   87: aload_0
    //   88: invokestatic 219	org/apache/http/params/HttpProtocolParams:setUserAgent	(Lorg/apache/http/params/HttpParams;Ljava/lang/String;)V
    //   91: new 221	org/apache/http/conn/scheme/SchemeRegistry
    //   94: dup
    //   95: invokespecial 222	org/apache/http/conn/scheme/SchemeRegistry:<init>	()V
    //   98: astore 4
    //   100: aload 4
    //   102: new 224	org/apache/http/conn/scheme/Scheme
    //   105: dup
    //   106: ldc 226
    //   108: invokestatic 232	org/apache/http/conn/scheme/PlainSocketFactory:getSocketFactory	()Lorg/apache/http/conn/scheme/PlainSocketFactory;
    //   111: bipush 80
    //   113: invokespecial 235	org/apache/http/conn/scheme/Scheme:<init>	(Ljava/lang/String;Lorg/apache/http/conn/scheme/SocketFactory;I)V
    //   116: invokevirtual 239	org/apache/http/conn/scheme/SchemeRegistry:register	(Lorg/apache/http/conn/scheme/Scheme;)Lorg/apache/http/conn/scheme/Scheme;
    //   119: pop
    //   120: aconst_null
    //   121: astore 6
    //   123: aload_3
    //   124: ifnull +67 -> 191
    //   127: iconst_2
    //   128: anewarray 36	java/lang/Class
    //   131: astore 13
    //   133: aload 13
    //   135: iconst_0
    //   136: getstatic 244	java/lang/Integer:TYPE	Ljava/lang/Class;
    //   139: aastore
    //   140: aload 13
    //   142: iconst_1
    //   143: getstatic 42	com/google/android/vending/expansion/downloader/impl/AndroidHttpClient:sSslSessionCacheClass	Ljava/lang/Class;
    //   146: aastore
    //   147: ldc 246
    //   149: ldc 248
    //   151: aload 13
    //   153: invokevirtual 252	java/lang/Class:getDeclaredMethod	(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;
    //   156: astore 14
    //   158: iconst_2
    //   159: anewarray 4	java/lang/Object
    //   162: astore 15
    //   164: aload 15
    //   166: iconst_0
    //   167: ldc 13
    //   169: invokestatic 256	java/lang/Integer:valueOf	(I)Ljava/lang/Integer;
    //   172: aastore
    //   173: aload 15
    //   175: iconst_1
    //   176: aload_3
    //   177: aastore
    //   178: aload 14
    //   180: aconst_null
    //   181: aload 15
    //   183: invokevirtual 262	java/lang/reflect/Method:invoke	(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
    //   186: checkcast 264	org/apache/http/conn/scheme/SocketFactory
    //   189: astore 6
    //   191: aload 6
    //   193: ifnonnull +8 -> 201
    //   196: invokestatic 269	org/apache/http/conn/ssl/SSLSocketFactory:getSocketFactory	()Lorg/apache/http/conn/ssl/SSLSocketFactory;
    //   199: astore 6
    //   201: aload 4
    //   203: new 224	org/apache/http/conn/scheme/Scheme
    //   206: dup
    //   207: ldc_w 271
    //   210: aload 6
    //   212: sipush 443
    //   215: invokespecial 235	org/apache/http/conn/scheme/Scheme:<init>	(Ljava/lang/String;Lorg/apache/http/conn/scheme/SocketFactory;I)V
    //   218: invokevirtual 239	org/apache/http/conn/scheme/SchemeRegistry:register	(Lorg/apache/http/conn/scheme/Scheme;)Lorg/apache/http/conn/scheme/Scheme;
    //   221: pop
    //   222: new 2	com/google/android/vending/expansion/downloader/impl/AndroidHttpClient
    //   225: dup
    //   226: new 273	org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager
    //   229: dup
    //   230: aload_2
    //   231: aload 4
    //   233: invokespecial 276	org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager:<init>	(Lorg/apache/http/params/HttpParams;Lorg/apache/http/conn/scheme/SchemeRegistry;)V
    //   236: aload_2
    //   237: invokespecial 278	com/google/android/vending/expansion/downloader/impl/AndroidHttpClient:<init>	(Lorg/apache/http/conn/ClientConnectionManager;Lorg/apache/http/params/HttpParams;)V
    //   240: areturn
    //   241: astore 22
    //   243: aload 22
    //   245: invokevirtual 281	java/lang/SecurityException:printStackTrace	()V
    //   248: aconst_null
    //   249: astore_3
    //   250: goto -164 -> 86
    //   253: astore 21
    //   255: aload 21
    //   257: invokevirtual 282	java/lang/NoSuchMethodException:printStackTrace	()V
    //   260: aconst_null
    //   261: astore_3
    //   262: goto -176 -> 86
    //   265: astore 20
    //   267: aload 20
    //   269: invokevirtual 283	java/lang/IllegalArgumentException:printStackTrace	()V
    //   272: aconst_null
    //   273: astore_3
    //   274: goto -188 -> 86
    //   277: astore 19
    //   279: aload 19
    //   281: invokevirtual 284	java/lang/InstantiationException:printStackTrace	()V
    //   284: aconst_null
    //   285: astore_3
    //   286: goto -200 -> 86
    //   289: astore 18
    //   291: aload 18
    //   293: invokevirtual 285	java/lang/IllegalAccessException:printStackTrace	()V
    //   296: aconst_null
    //   297: astore_3
    //   298: goto -212 -> 86
    //   301: astore 17
    //   303: aload 17
    //   305: invokevirtual 286	java/lang/reflect/InvocationTargetException:printStackTrace	()V
    //   308: aconst_null
    //   309: astore_3
    //   310: goto -224 -> 86
    //   313: astore 12
    //   315: aload 12
    //   317: invokevirtual 281	java/lang/SecurityException:printStackTrace	()V
    //   320: aconst_null
    //   321: astore 6
    //   323: goto -132 -> 191
    //   326: astore 11
    //   328: aload 11
    //   330: invokevirtual 282	java/lang/NoSuchMethodException:printStackTrace	()V
    //   333: aconst_null
    //   334: astore 6
    //   336: goto -145 -> 191
    //   339: astore 10
    //   341: aload 10
    //   343: invokevirtual 283	java/lang/IllegalArgumentException:printStackTrace	()V
    //   346: aconst_null
    //   347: astore 6
    //   349: goto -158 -> 191
    //   352: astore 9
    //   354: aload 9
    //   356: invokevirtual 285	java/lang/IllegalAccessException:printStackTrace	()V
    //   359: aconst_null
    //   360: astore 6
    //   362: goto -171 -> 191
    //   365: astore 8
    //   367: aload 8
    //   369: invokevirtual 286	java/lang/reflect/InvocationTargetException:printStackTrace	()V
    //   372: aconst_null
    //   373: astore 6
    //   375: goto -184 -> 191
    //
    // Exception table:
    //   from	to	target	type
    //   55	83	241	java/lang/SecurityException
    //   55	83	253	java/lang/NoSuchMethodException
    //   55	83	265	java/lang/IllegalArgumentException
    //   55	83	277	java/lang/InstantiationException
    //   55	83	289	java/lang/IllegalAccessException
    //   55	83	301	java/lang/reflect/InvocationTargetException
    //   127	191	313	java/lang/SecurityException
    //   127	191	326	java/lang/NoSuchMethodException
    //   127	191	339	java/lang/IllegalArgumentException
    //   127	191	352	java/lang/IllegalAccessException
    //   127	191	365	java/lang/reflect/InvocationTargetException
  }

  public static long parseDate(String paramString)
  {
    return HttpDateTime.parse(paramString);
  }

  private static String toCurl(HttpUriRequest paramHttpUriRequest, boolean paramBoolean)
    throws IOException
  {
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("curl ");
    Header[] arrayOfHeader = paramHttpUriRequest.getAllHeaders();
    int i = arrayOfHeader.length;
    int j = 0;
    if (j < i)
    {
      Header localHeader = arrayOfHeader[j];
      if ((!paramBoolean) && ((localHeader.getName().equals("Authorization")) || (localHeader.getName().equals("Cookie"))));
      while (true)
      {
        j++;
        break;
        localStringBuilder.append("--header \"");
        localStringBuilder.append(localHeader.toString().trim());
        localStringBuilder.append("\" ");
      }
    }
    URI localURI = paramHttpUriRequest.getURI();
    if ((paramHttpUriRequest instanceof RequestWrapper))
    {
      HttpRequest localHttpRequest = ((RequestWrapper)paramHttpUriRequest).getOriginal();
      if ((localHttpRequest instanceof HttpUriRequest))
        localURI = ((HttpUriRequest)localHttpRequest).getURI();
    }
    localStringBuilder.append("\"");
    localStringBuilder.append(localURI);
    localStringBuilder.append("\"");
    if ((paramHttpUriRequest instanceof HttpEntityEnclosingRequest))
    {
      HttpEntity localHttpEntity = ((HttpEntityEnclosingRequest)paramHttpUriRequest).getEntity();
      if ((localHttpEntity != null) && (localHttpEntity.isRepeatable()))
      {
        if (localHttpEntity.getContentLength() >= 1024L)
          break label283;
        ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
        localHttpEntity.writeTo(localByteArrayOutputStream);
        String str = localByteArrayOutputStream.toString();
        localStringBuilder.append(" --data-ascii \"").append(str).append("\"");
      }
    }
    while (true)
    {
      return localStringBuilder.toString();
      label283: localStringBuilder.append(" [TOO MUCH DATA TO INCLUDE]");
    }
  }

  public void close()
  {
    if (this.mLeakedException != null)
    {
      getConnectionManager().shutdown();
      this.mLeakedException = null;
    }
  }

  public void disableCurlLogging()
  {
    this.curlConfiguration = null;
  }

  public void enableCurlLogging(String paramString, int paramInt)
  {
    if (paramString == null)
      throw new NullPointerException("name");
    if ((paramInt < 2) || (paramInt > 7))
      throw new IllegalArgumentException("Level is out of range [2..7]");
    this.curlConfiguration = new LoggingConfiguration(paramString, paramInt, null);
  }

  public <T> T execute(HttpHost paramHttpHost, HttpRequest paramHttpRequest, ResponseHandler<? extends T> paramResponseHandler)
    throws IOException, ClientProtocolException
  {
    return this.delegate.execute(paramHttpHost, paramHttpRequest, paramResponseHandler);
  }

  public <T> T execute(HttpHost paramHttpHost, HttpRequest paramHttpRequest, ResponseHandler<? extends T> paramResponseHandler, HttpContext paramHttpContext)
    throws IOException, ClientProtocolException
  {
    return this.delegate.execute(paramHttpHost, paramHttpRequest, paramResponseHandler, paramHttpContext);
  }

  public <T> T execute(HttpUriRequest paramHttpUriRequest, ResponseHandler<? extends T> paramResponseHandler)
    throws IOException, ClientProtocolException
  {
    return this.delegate.execute(paramHttpUriRequest, paramResponseHandler);
  }

  public <T> T execute(HttpUriRequest paramHttpUriRequest, ResponseHandler<? extends T> paramResponseHandler, HttpContext paramHttpContext)
    throws IOException, ClientProtocolException
  {
    return this.delegate.execute(paramHttpUriRequest, paramResponseHandler, paramHttpContext);
  }

  public HttpResponse execute(HttpHost paramHttpHost, HttpRequest paramHttpRequest)
    throws IOException
  {
    return this.delegate.execute(paramHttpHost, paramHttpRequest);
  }

  public HttpResponse execute(HttpHost paramHttpHost, HttpRequest paramHttpRequest, HttpContext paramHttpContext)
    throws IOException
  {
    return this.delegate.execute(paramHttpHost, paramHttpRequest, paramHttpContext);
  }

  public HttpResponse execute(HttpUriRequest paramHttpUriRequest)
    throws IOException
  {
    return this.delegate.execute(paramHttpUriRequest);
  }

  public HttpResponse execute(HttpUriRequest paramHttpUriRequest, HttpContext paramHttpContext)
    throws IOException
  {
    return this.delegate.execute(paramHttpUriRequest, paramHttpContext);
  }

  protected void finalize()
    throws Throwable
  {
    super.finalize();
    if (this.mLeakedException != null)
    {
      Log.e("AndroidHttpClient", "Leak found", this.mLeakedException);
      this.mLeakedException = null;
    }
  }

  public ClientConnectionManager getConnectionManager()
  {
    return this.delegate.getConnectionManager();
  }

  public HttpParams getParams()
  {
    return this.delegate.getParams();
  }

  private class CurlLogger
    implements HttpRequestInterceptor
  {
    private CurlLogger()
    {
    }

    public void process(HttpRequest paramHttpRequest, HttpContext paramHttpContext)
      throws HttpException, IOException
    {
      AndroidHttpClient.LoggingConfiguration localLoggingConfiguration = AndroidHttpClient.this.curlConfiguration;
      if ((localLoggingConfiguration != null) && (AndroidHttpClient.LoggingConfiguration.access$400(localLoggingConfiguration)) && ((paramHttpRequest instanceof HttpUriRequest)))
        AndroidHttpClient.LoggingConfiguration.access$600(localLoggingConfiguration, AndroidHttpClient.toCurl((HttpUriRequest)paramHttpRequest, false));
    }
  }

  private static class LoggingConfiguration
  {
    private final int level;
    private final String tag;

    private LoggingConfiguration(String paramString, int paramInt)
    {
      this.tag = paramString;
      this.level = paramInt;
    }

    private boolean isLoggable()
    {
      return Log.isLoggable(this.tag, this.level);
    }

    private void println(String paramString)
    {
      Log.println(this.level, this.tag, paramString);
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.google.android.vending.expansion.downloader.impl.AndroidHttpClient
 * JD-Core Version:    0.6.2
 */